package com.powernode;

import com.powernode.dto.LoginUser;
import io.minio.messages.DeleteObject;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

public class test {

    @Test
    void test(){
        List<String> files = new ArrayList<>();
        files.add("01.jpg");
        files.add("02.jpg");
        files.add("03.jpg");
        List<BigDecimal> list = new ArrayList<>();
        // 使用stream流获取集合元素总和
        // BigDecimal类型总和
        //BigDecimal reduce = list.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
        // int类型总和
        // list.stream().mapToInt(i -> i).sum()
//        List<DeleteObject> dos = files.stream().map(e -> new DeleteObject(e)).collect(Collectors.toList());
        List<DeleteObject> dos = new LinkedList<>();
        dos.add(new DeleteObject("01.jpg"));
        dos.add(new DeleteObject("01.jpg"));
        dos.add(new DeleteObject("01.jpg"));
        for (DeleteObject item : dos) {
            System.out.println("item = " + item.toString());
        }
    }
    @Test
    void test1(){
        LoginUser loginUser = new LoginUser();
        loginUser = null;
        //loginUser.setId(11L);
        Long id = Optional.ofNullable(loginUser).map(LoginUser::getId).orElse(null);

        System.out.println("id = " + id);

    }

    @Test
    void test2(){
        Map<String, String> map = new HashMap<>();
        map.put("free","1.com");
        map.put("vip","2.com");
        String next = map.keySet().iterator().next();
        System.out.println("next = " + next);

        List<String> list = new ArrayList<>();
        list.add("free");
        list.add("admin");
        List<String> collect = list.stream().map(i -> "ROLE_" + i).collect(Collectors.toList());
        collect.forEach(System.out::println);
    }
}
